package com.filter.example;

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

// @WebFilter(filterName = "MyFilterDemo01", urlPatterns = "/MyServlet")
public class MyFilterDemo01 implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        // PrintWriter out = response.getWriter();
        // out.print("因为使用了拦截器，在浏览器中输出本行文字，不会显示登录界面。");
        // chain.doFilter(request, response);
        // 用于拦截用户的请求，如果和当前过滤器的拦截路径匹配，该方法会被调用
        PrintWriter out=response.getWriter();
        out.write("该页面显示了对请求进行拦截之后出现的页面...");
        // chain.doFilter(request, response);
    }
}
